#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : bigDataProject 
@File    : base_middle_api.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/11/11 17:59 
@Describe: 餐饮中台接口请求基类
"""
from typing import Text, Dict

from api.base_api import BaseAPI


class BaseMiddleAPI(BaseAPI):

    def __init__(self, env: Text) -> None:
        """
        构造函数
        :param env: 环境编码
        """
        super().__init__()
        self.TYPE = "餐饮中台"
        credentials_sql = "SELECT url_prefix,token FROM login_credentials WHERE environment = '{}' " \
                          "AND type = '{}'".format(env, self.TYPE)
        credentials_result = self.sqlite.query_data(credentials_sql)[0]
        self.URL = credentials_result[0]
        self.token = credentials_result[1]

    def get_headers(self) -> Dict:
        headers = {
            'Connection': 'keep-alive',
            'j_token': self.token,
            'Content-Type': 'application/json; charset=UTF-8',
            'sec-ch-ua-mobile': '?0',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
            'Accept': '*/*',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cookie': 'SERVERID=k8s-ingress.gtmsh.com:10080; j_token=' + self.token
        }
        return headers


if __name__ == '__main__':
    test = BaseMiddleAPI('sit')
    url = 'catering-backend/shop/base/list'
    payload = '{"brandCode":"823882","shopCode":"5999"}'
    test.http_request(url, payload, "获取门店列表接口")
